home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / gas_251.zip / bin_251 / bfd / osf-core.c < prev    next >
C/C++ Source or Header  |  1994-08-24  |  7KB  |  259 lines

  1. /* BFD back-end for OSF/1 core files.
  2.    Copyright 1993, 1994 Free Software Foundation, Inc.
  3.  
  4. This file is part of BFD, the Binary File Descriptor library.
  5.  
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. /* This file can only be compiled on systems which use OSF/1 style
  21.    core files.  In the config/XXXXXX.mh file for such a system add
  22.       HDEFINES=-DOSF_CORE
  23.       HDEPFILES=osf-core.o
  24.    */
  25.  
  26. #include "bfd.h"
  27. #include "sysdep.h"
  28. #include "libbfd.h"
  29.  
  30. #include <stdio.h>
  31. #include <string.h>
  32. #include <sys/user.h>
  33. #include <sys/core.h>
  34.  
  35. /* forward declarations */
  36.  
  37. static asection *
  38. make_bfd_asection PARAMS ((bfd *, CONST char *, flagword, bfd_size_type,
  39.                bfd_vma, file_ptr));
  40. static asymbol *
  41. osf_core_make_empty_symbol PARAMS ((bfd *));
  42. static const bfd_target *
  43. osf_core_core_file_p PARAMS ((bfd *));
  44. static char *
  45. osf_core_core_file_failing_command PARAMS ((bfd *));
  46. static int
  47. osf_core_core_file_failing_signal PARAMS ((bfd *));
  48. static boolean
  49. osf_core_core_file_matches_executable_p PARAMS ((bfd *, bfd *));
  50. static void
  51. swap_abort PARAMS ((void));
  52.  
  53. /* These are stored in the bfd's tdata */
  54.  
  55. struct osf_core_struct 
  56. {
  57.   int sig;
  58.   char cmd[MAXCOMLEN + 1];
  59. };
  60.  
  61. #define core_hdr(bfd) ((bfd)->tdata.osf_core_data)
  62. #define core_signal(bfd) (core_hdr(bfd)->sig)
  63. #define core_command(bfd) (core_hdr(bfd)->cmd)
  64.  
  65. static asection *
  66. make_bfd_asection (abfd, name, flags, _raw_size, vma, filepos)
  67.      bfd *abfd;
  68.      CONST char *name;
  69.      flagword flags;
  70.      bfd_size_type _raw_size;
  71.      bfd_vma vma;
  72.      file_ptr filepos;
  73. {
  74.   asection *asect;
  75.  
  76.   asect = bfd_make_section_anyway (abfd, name);
  77.   if (!asect)
  78.     return NULL;
  79.  
  80.   asect->flags = flags;
  81.   asect->_raw_size = _raw_size;
  82.   asect->vma = vma;
  83.   asect->filepos = filepos;
  84.   asect->alignment_power = 8;
  85.  
  86.   return asect;
  87. }
  88.  
  89. static asymbol *
  90. osf_core_make_empty_symbol (abfd)
  91.      bfd *abfd;
  92. {
  93.   asymbol *new = (asymbol *) bfd_zalloc (abfd, sizeof (asymbol));
  94.   if (new)
  95.     new->the_bfd = abfd;
  96.   return new;
  97. }
  98.  
  99. static const bfd_target *
  100. osf_core_core_file_p (abfd)
  101.      bfd *abfd;
  102. {
  103.   int val;
  104.   int i;
  105.   char *secname;
  106.   struct core_filehdr core_header;
  107.  
  108.   val = bfd_read ((PTR)&core_header, 1, sizeof core_header, abfd);
  109.   if (val != sizeof core_header)
  110.     return NULL;
  111.  
  112.   if (strncmp (core_header.magic, "Core", 4) != 0)
  113.     return NULL;
  114.  
  115.   core_hdr (abfd) = (struct osf_core_struct *)
  116.     bfd_zalloc (abfd, sizeof (struct osf_core_struct));
  117.   if (!core_hdr (abfd))
  118.     return NULL;
  119.  
  120.   strncpy (core_command (abfd), core_header.name, MAXCOMLEN + 1);
  121.   core_signal (abfd) = core_header.signo;
  122.  
  123.   for (i = 0; i < core_header.nscns; i++)
  124.     {
  125.       struct core_scnhdr core_scnhdr;
  126.       flagword flags;
  127.  
  128.       val = bfd_read ((PTR)&core_scnhdr, 1, sizeof core_scnhdr, abfd);
  129.       if (val != sizeof core_scnhdr)
  130.     break;
  131.  
  132.       /* Skip empty sections.  */
  133.       if (core_scnhdr.size == 0 || core_scnhdr.scnptr == 0)
  134.     continue;
  135.  
  136.       switch (core_scnhdr.scntype)
  137.     {
  138.     case SCNRGN:
  139.       secname = ".data";
  140.       flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
  141.       break;
  142.     case SCNSTACK:
  143.       secname = ".stack";
  144.       flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
  145.       break;
  146.     case SCNREGS:
  147.       secname = ".reg";
  148.       flags = SEC_HAS_CONTENTS;
  149.       break;
  150.     default:
  151.       fprintf (stderr, "Unhandled OSF/1 core file section type %d\n",
  152.            core_scnhdr.scntype);
  153.       continue;
  154.     }
  155.  
  156.       if (!make_bfd_asection (abfd, secname, flags,
  157.                   (bfd_size_type) core_scnhdr.size,
  158.                   (bfd_vma) core_scnhdr.vaddr,
  159.                   (file_ptr) core_scnhdr.scnptr))
  160.     return NULL;
  161.     }
  162.  
  163.   /* OK, we believe you.  You're a core file (sure, sure).  */
  164.  
  165.   return abfd->xvec;
  166. }
  167.  
  168. static char *
  169. osf_core_core_file_failing_command (abfd)
  170.      bfd *abfd;
  171. {
  172.   return core_command (abfd);
  173. }
  174.  
  175. /* ARGSUSED */
  176. static int
  177. osf_core_core_file_failing_signal (abfd)
  178.      bfd *abfd;
  179. {
  180.   return core_signal (abfd);
  181. }
  182.  
  183. /* ARGSUSED */
  184. static boolean
  185. osf_core_core_file_matches_executable_p (core_bfd, exec_bfd)
  186.      bfd *core_bfd, *exec_bfd;
  187. {
  188.   return true;        /* FIXME, We have no way of telling at this point */
  189. }
  190.  
  191. #define osf_core_get_symtab_upper_bound _bfd_nosymbols_get_symtab_upper_bound
  192. #define osf_core_get_symtab _bfd_nosymbols_get_symtab
  193. #define osf_core_print_symbol _bfd_nosymbols_print_symbol
  194. #define osf_core_get_symbol_info _bfd_nosymbols_get_symbol_info
  195. #define osf_core_bfd_is_local_label _bfd_nosymbols_bfd_is_local_label
  196. #define osf_core_get_lineno _bfd_nosymbols_get_lineno
  197. #define osf_core_find_nearest_line _bfd_nosymbols_find_nearest_line
  198. #define osf_core_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
  199.  
  200. /* If somebody calls any byte-swapping routines, shoot them.  */
  201. static void
  202. swap_abort()
  203. {
  204.   abort(); /* This way doesn't require any declaration for ANSI to fuck up */
  205. }
  206. #define    NO_GET    ((bfd_vma (*) PARAMS ((   const bfd_byte *))) swap_abort )
  207. #define    NO_PUT    ((void    (*) PARAMS ((bfd_vma, bfd_byte *))) swap_abort )
  208. #define    NO_SIGNED_GET \
  209.   ((bfd_signed_vma (*) PARAMS ((const bfd_byte *))) swap_abort )
  210.  
  211. const bfd_target osf_core_vec =
  212.   {
  213.     "osf-core",
  214.     bfd_target_unknown_flavour,
  215.     true,            /* target byte order */
  216.     true,            /* target headers byte order */
  217.     (HAS_RELOC | EXEC_P |    /* object flags */
  218.      HAS_LINENO | HAS_DEBUG |
  219.      HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
  220.     (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
  221.     0,                                               /* symbol prefix */
  222.     ' ',                           /* ar_pad_char */
  223.     16,                               /* ar_max_namelen */
  224.     3,                               /* minimum alignment power */
  225.     NO_GET, NO_SIGNED_GET, NO_PUT,    /* 64 bit data */
  226.     NO_GET, NO_SIGNED_GET, NO_PUT,    /* 32 bit data */
  227.     NO_GET, NO_SIGNED_GET, NO_PUT,    /* 16 bit data */
  228.     NO_GET, NO_SIGNED_GET, NO_PUT,    /* 64 bit hdrs */
  229.     NO_GET, NO_SIGNED_GET, NO_PUT,    /* 32 bit hdrs */
  230.     NO_GET, NO_SIGNED_GET, NO_PUT,    /* 16 bit hdrs */
  231.  
  232.     {                /* bfd_check_format */
  233.      _bfd_dummy_target,        /* unknown format */
  234.      _bfd_dummy_target,        /* object file */
  235.      _bfd_dummy_target,        /* archive */
  236.      osf_core_core_file_p    /* a core file */
  237.     },
  238.     {                /* bfd_set_format */
  239.      bfd_false, bfd_false,
  240.      bfd_false, bfd_false
  241.     },
  242.     {                /* bfd_write_contents */
  243.      bfd_false, bfd_false,
  244.      bfd_false, bfd_false
  245.     },
  246.     
  247.        BFD_JUMP_TABLE_GENERIC (_bfd_generic),
  248.        BFD_JUMP_TABLE_COPY (_bfd_generic),
  249.        BFD_JUMP_TABLE_CORE (osf_core),
  250.        BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
  251.        BFD_JUMP_TABLE_SYMBOLS (osf_core),
  252.        BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
  253.        BFD_JUMP_TABLE_WRITE (_bfd_generic),
  254.        BFD_JUMP_TABLE_LINK (_bfd_nolink),
  255.        BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
  256.  
  257.     (PTR) 0            /* backend_data */
  258. };
  259.